#include "head.h"
/* Usage: */

void *thread_main(void *p){
    status_t *status = (status_t*)p;
    
    while(1){
        pthread_mutex_lock(&status->lock);

        while(isEmpty(status->net_q) && status->exit_flag==false){
            pthread_cond_wait(&status->cond, &status->lock);
        }
        
        if(status->exit_flag){
            //printf("exit!!!!\n");
            pthread_mutex_unlock(&status->lock);
            pthread_exit(NULL);
        }

        client_status* user = pop(status->net_q);
        pthread_mutex_unlock(&status->lock);
        printf("与%d客户端开始工作！\n", user->net_fd);
        work(user, *status);
        printf("与%d客户端工作完成！\n", user->net_fd);
        close(user->net_fd);
    }

    return NULL;
}
